home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / func_if.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  927 b   |  35 lines  |  [TEXT/ttxt]

  1. #
  2. # Init section
  3. #
  4. drop table if exists t1;
  5.  
  6. #
  7. # Simple IF tests
  8. #
  9.  
  10. select IF(0,"ERROR","this"),IF(1,"is","ERROR"),IF(NULL,"ERROR","a"),IF(1,2,3)|0,IF(1,2.0,3.0)+0 ;
  11.  
  12. #
  13. # Test of IF and case-sensitiveness
  14. #
  15. CREATE TABLE t1 (st varchar(255) NOT NULL, u int(11) NOT NULL) TYPE=MyISAM;
  16. INSERT INTO t1 VALUES ('a',1),('A',1),('aa',1),('AA',1),('a',1),('aaa',0),('BBB',0);
  17. select if(1,st,st) s from t1 order by s;
  18. select if(u=1,st,st) s from t1 order by s;
  19. select if(u=1,binary st,st) s from t1 order by s;
  20. select if(u=1,st,binary st) s from t1 where st like "%a%" order by s;
  21. drop table t1;
  22.  
  23. #
  24. # Problem with IF()
  25. #
  26.  
  27. create table t1 (num  double(12,2));
  28. insert into t1 values (144.54);
  29. select sum(if(num is null,0.00,num)) from t1;
  30. drop table t1;
  31. create table t1 (x int, y int);
  32. insert into t1 values (0,6),(10,16),(20,26),(30,10),(40,46),(50,56);
  33. select min(if(y -x > 5,y,NULL)), max(if(y - x > 5,y,NULL)) from t1;
  34. drop table t1;
  35.